#导入需要的库
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score

#提取特征，划分数据集
x,y=load_iris().data,load_iris().target
x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=1,test_size=50)

#定义与训练模型
model=GaussianNB()
model.fit(x_train,y_train)

#模型评估
pred=model.predict(x_test)
print("测试集数据的预测标签为",pred)
print("测试集数据的真实标签为",y_test)
print("测试集共有%d条数据，其中预测错误的数据有%d条，预测准确率为%.2f"%(x_test.shape[0],(pred!=y_test).sum(),accuracy_score(y_test,pred)))